using System;
using System.Web;
using log4net;

namespace DailyReport.Core.Util
{
    public class NHibernateSessionHTTPModule : IHttpModule
    {
        ILog log = LogManager.GetLogger("NHibernateSessionHTTPModule");
        
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
            context.EndRequest += new EventHandler(context_EndRequest);
        }

        private void context_EndRequest(object sender, EventArgs e)
        {
            log.Debug("context_EndRequest");
            ConnectionManager.Instance.EndSession(sender);
        }

        private void context_BeginRequest(object sender, EventArgs e)
        {
            log.Debug("context_BeginRequest");
            ConnectionManager.Instance.StartSession(sender);
        }

        public void Dispose()
        {
        }
    }
}